import time
from functools import wraps

ONE_DAY = 24 * 60 * 60
ONE_HOUR = 1 * 60 * 60

# TODO: make arguments caching


def cache_for_time(func, ttl: int):
    cache = []
    last_call_time = 0

    @wraps(func)
    async def wrapper(*args, **kwargs):
        nonlocal cache, last_call_time

        if time.monotonic() - last_call_time < ttl and cache:
            return cache

        result = await func(*args, **kwargs)

        cache = result
        last_call_time = time.monotonic()

        return result

    return wrapper


def cache_for_day(func):
    return cache_for_time(func, ONE_DAY)


def cache_for_hour(func):
    return cache_for_time(func, ONE_HOUR)
